<?php

use yii\db\Migration;
use yii\db\Schema;

class m170117_013304_CREATE_ORDER_DEV extends Migration
{
    public function up()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 订单基础信息
        $this->createTable('order', [
            "id" =>         Schema::TYPE_PK,
            "product_id"=>  Schema::TYPE_INTEGER.    "(9) NOT NULL COMMENT '所属团期(航线)'",
            "code" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '订单编号'",
            "total_sale" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '总金额'",
            "sale_price" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '优惠金额'",
            "price" =>      Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '实际金额=总-优惠'",
            "source" =>     Schema::TYPE_INTEGER.   "(2) DEFAULT  '0' COMMENT '众信 ，国旅 ，途牛...'",
            "remark"=>      Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME.  " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 订单人员信息
        $this->createTable('order_customer', [
            "id" =>           Schema::TYPE_PK,
            "order_id"=>      Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属订单'",
            "first_name" =>   Schema::TYPE_STRING.    "(32) NULL COMMENT '姓'",
            "last_name" =>    Schema::TYPE_STRING.    "(32) NULL COMMENT '名'",
            "en_first_name"=> Schema::TYPE_STRING.    "(32) NULL COMMENT '英文姓'",
            "en_last_name"=>  Schema::TYPE_STRING.    "(32) NULL COMMENT '英文名'",
            "pinyin"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '名字拼音'",
            "gender" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '0' COMMENT '1 男 2 女'",
            "birthday" =>     Schema::TYPE_DATE.      " NULL COMMENT '出生日期'",
            "country"=>       Schema::TYPE_STRING.    "(64) NULL COMMENT '国籍'",
            "passport"=>      Schema::TYPE_STRING.    "(255) NULL COMMENT '护照号码'",
            "passport_add"=>  Schema::TYPE_STRING.    "(255) NULL COMMENT '护照签发地'",
            "passport_date"=> Schema::TYPE_DATE.      " NULL COMMENT '护照有效期'",
            "passport_type"=> Schema::TYPE_INTEGER.   "(1) DEFAULT  '0' COMMENT '护照类型 1 原件 2 复印件'",
            "phone"=>         Schema::TYPE_STRING.    "(64) NULL COMMENT '手机号'",
            "remark"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 订单舱房信息
        $this->createTable('order_room', [
            "id" =>           Schema::TYPE_PK,
            "order_id"=>      Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属订单'",
            "customer_id"=>   Schema::TYPE_INTEGER.   "(11) NULL COMMENT '客户编号'",
            "room_id"=>       Schema::TYPE_INTEGER.   "(9)  NULL COMMENT '舱房编号'",
            "price" =>        Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '价格'",
            "remark"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 订单机票信息
        $this->createTable('order_flight', [
            "id" =>           Schema::TYPE_PK,
            "order_id"=>      Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属订单'",
            "customer_id"=>   Schema::TYPE_INTEGER.   "(11) NULL COMMENT '客户编号'",
            "room_id"=>       Schema::TYPE_INTEGER.   "(9)  NULL COMMENT '舱房编号'",
            "price" =>        Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '价格'",
            "remark"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 订单地接酒店信息
        $this->createTable('order_group', [
            "id" =>           Schema::TYPE_PK,
            "order_id"=>      Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属订单'",
            "customer_id"=>   Schema::TYPE_INTEGER.   "(11) NULL COMMENT '客户编号'",
            "group_id"=>      Schema::TYPE_INTEGER.   "(9)  NULL COMMENT '地接产品(酒店)编号'",
            "price" =>        Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '价格'",
            "remark"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 订单游览(岸上游)信息
        $this->createTable('order_visit', [
            "id" =>           Schema::TYPE_PK,
            "order_id"=>      Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属订单'",
            "customer_id"=>   Schema::TYPE_INTEGER.   "(11) NULL COMMENT '客户编号'",
            "visit_id"=>      Schema::TYPE_INTEGER.   "(9)  NULL COMMENT '岸上游产品编号'",
            "price" =>        Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '价格'",
            "remark"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);



        // 订单联系人信息
        $this->createTable('order_contact', [
            "id" =>           Schema::TYPE_PK,
            "order_id"=>      Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属订单'",
            "customer_id"=>   Schema::TYPE_INTEGER.   "(11) NULL COMMENT '客户编号'",
            "name"=>          Schema::TYPE_STRING.    "(255) NULL COMMENT '姓名'",
            "gender" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '0' COMMENT '1 男 2 女'",
            "phone"=>         Schema::TYPE_STRING.    "(64) NULL COMMENT '手机号'",
            "mail"=>          Schema::TYPE_STRING.    "(255) NULL COMMENT '邮箱'",
            "remark"=>        Schema::TYPE_STRING.    "(255) NULL COMMENT '备注说明'",

            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);







    }

    public function down()
    {
        echo "m170117_013304_CREATE_ORDER_DEV cannot be reverted.\n";
        $this->dropTable('order');
        $this->dropTable('order_customer');
        $this->dropTable('order_room');
        $this->dropTable('order_flight');
        $this->dropTable('order_group');
        $this->dropTable('order_visit');
        $this->dropTable('order_contact');

        return false;
    }
   
}
